﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dev.Control;
using Bill.BasDLL.biz;
using TT.Common;
using Bill.BasDLL.ety;

namespace Bill.BasForm.sfcorpBill
{
    public partial class frmBillPriceCopy : BaseFormDev
    {
        bizBillPrice bzBillPrice;
        TT.Module.sysLogin.etyBaeSystemParamter basSysPara;
        TT.Module.GetSqliBaseData sqliBaseData;
        IList<etyBillPrice> ilPirce = new List<etyBillPrice>();

        public frmBillPriceCopy(TT.Module.sysLogin.etyBaeSystemParamter basSysPara,IList<etyBillPrice> _ilPrice)
        {
            this.ilPirce = _ilPrice;
            this.basSysPara = basSysPara;
            this.sqliBaseData = new TT.Module.GetSqliBaseData(basSysPara.SqliBaseHelp);
            InitializeComponent();
        }

        #region 事件

        //显示行号
        private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
                }
                else if (e.RowHandle < 0 && e.RowHandle > -1000)
                {
                    e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
                    e.Info.DisplayText = "G" + e.RowHandle.ToString();
                }
            }
        }
        private void frmBillPrice_Load(object sender, EventArgs e)
        {
            bzBillPrice = new bizBillPrice(basSysPara);

            #region 下拉数据
            IList<Bill.BasDLL.ety.etyCustomer> ilCust = dataProcessor.CopyIList<Bill.BasDLL.ety.etyCustomer>(sqliBaseData.GetBaseData<Bill.BasDLL.ety.etyCustomer>(basSysPara.PORT_CODE, "CBO_C_CUSTOMER"));
            ilCust.Insert(0, new BasDLL.ety.etyCustomer() { CUSTOMER_ID = "***", CUSTOMER_NAM = "***" });
            cboCustomer.DataSource = ilCust;

            IList<TT.ORM.etyCodeRef> ilItem = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_BILL_CODE"));
            cboItem.DataSource = ilItem;

            IList<TT.ORM.etyCodeRef> ilPort = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_PORT"));
            ilPort.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboPortId.DataSource = ilPort;

            IList<TT.ORM.etyCodeRef> ilIE = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_I_E"));
            ilIE.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboIeId.DataSource = ilIE;

            IList<TT.ORM.etyCodeRef> ilCntrCopr = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_CNTR_CORP"));
            ilCntrCopr.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboCntrCoprCod.DataSource = ilCntrCopr;

            IList<TT.ORM.etyCodeRef> ilFeeWay = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_FEE_WAY"));
            ilFeeWay.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboFeeWayId.DataSource = ilFeeWay;

            IList<TT.ORM.etyCodeRef> ilWorkWay = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_WORK_WAY"));
            ilWorkWay.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboWorkWayId.DataSource = ilWorkWay;

            IList<TT.ORM.etyCodeRef> ilCntrSize = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_CNTR_SIZ"));
            ilCntrSize.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboCntr_Siz_Cod.DataSource = ilCntrSize;

            IList<TT.ORM.etyCodeRef> ilCntrType = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_CNTR_TYP"));
            ilCntrType.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboCntr_Typ_Cod.DataSource = ilCntrType;

            IList<TT.ORM.etyCodeRef> ilWeight = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_SYS_YN"));
            ilWeight.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboWeight.DataSource = ilWeight;

            
            IList<TT.ORM.etyCodeRef> ilUnit = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_UNIT_REF"));
            cboUnit.DataSource = ilUnit;

            IList<TT.ORM.etyCodeRef> ilForeignVvd = dataProcessor.CopyIList<TT.ORM.etyCodeRef>(sqliBaseData.GetBaseData(basSysPara.PORT_CODE, "CBO_C_FOREIGN_VVD"));
            ilForeignVvd.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboForeignVvd.DataSource = ilForeignVvd;
            #endregion

            #region 表格数据
            ggcPrice.GridView = this.gridView1;
            ggcPrice.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            string sMapingCols = "CUSTOMER,CUSTOMER_NAME,ITEM,ITEM_DESC,CHRG_FLT1,CHRG_DESC1,CHRG_FLT2,CHRG_DESC2,CHRG_FLT3,CHRG_DESC3,CHRG_FLT9,CHRG_DESC9,CHRG_FLT4,CHRG_DESC4,CHRG_FLT5,CHRG_DESC5,CHRG_FLT6,CHRG_FLT7,CHRG_FLT8,UNIT,METHOD,PRICE";
            string sMapingHeaderTxt = "客户代码,客户名称,收费代码,费用描述,码头,码头名称,货代公司,货代名称,进出口,进出口描述,内外贸,内外贸描述,结算方式,结算方式描述,作业方式,作业方式描述,是否过磅,尺寸,箱型,单位,每方法,单价";
            ggcPrice.ColumnsMappingCreate(sMapingCols, sMapingHeaderTxt);
            this.winUtil.LoadGridLayout(ggcPrice);
            ggcPrice.GridView.OptionsView.ShowGroupPanel = true;
            srcBinding.DataSource = ilPirce;
            #endregion


            cboCustomer.SelectedIndex = -1;
            bar3.Text = "状态栏";

        }

        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SaveDate();
        }

        private void btnExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            F12();
        }
        #endregion


        public override etyQuickKey SaveDate()
        {
            IList<etyBillPrice> ilBillPrice=srcBinding.DataSource  as List<etyBillPrice>;
            bool rst=false;
            foreach (etyBillPrice ey in ilBillPrice)
            {
                rst = bzBillPrice.Insert(ey);
            }
            if (rst)
            {
                TT.HelpInfo.MsgBox.ShowSuccessBox("保存成功");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                RefreshDate();
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Abort;
                TT.HelpInfo.MsgBox.ShowWarnBox("保存失败");
            }
        return base.SaveDate();
        }

        #region 函数
        private void ClearForm()
        {
            cboCustomer.SelectedIndex = -1;
            cboItem.SelectedIndex = -1;
            //cboSvc_Type.SelectedIndex = -1;
            cboPortId.SelectedIndex = 0;
            cboCntrCoprCod.SelectedIndex = 0;
            cboIeId.SelectedIndex = 0;
            cboFeeWayId.SelectedIndex = 0;
            cboWorkWayId.SelectedIndex = 0;
            cboWeight.SelectedIndex = 0;
            cboCntr_Siz_Cod.SelectedIndex = 0;
            cboCntr_Typ_Cod.SelectedIndex = 0;
            cboForeignVvd.SelectedIndex = 0;
            cboUnit.SelectedIndex = -1;
        }
        #endregion

        private void cboForeignVvd_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            foreach (etyBillPrice ety in ilSrc)
            {
                string foreignVvd = cboForeignVvd.Value;
                ety.CHRG_FLT9 = foreignVvd;
                if (string.IsNullOrWhiteSpace(foreignVvd) || foreignVvd == "***")
                {
                    ety.CHRG_FLT9 = "***";
                    ety.CHRG_DESC9 = "***";
                }
                else
                    ety.CHRG_DESC9 = cboForeignVvd.GetValue("CODE_DESC");
                
            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboCustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboCustomer.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CUSTOMER = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CUSTOMER = "***";
                    ety.CUSTOMER_NAME = "***";
                }
                else
                    ety.CUSTOMER_NAME = cboCustomer.GetValue("CUSTOMER_NAM");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboPortId_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboPortId.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT1 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT1 = "***";
                    ety.CHRG_DESC1 = "***";
                }
                else
                    ety.CHRG_DESC1 = cboPortId.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboFeeWayId_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboFeeWayId.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT4 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT4 = "***";
                    ety.CHRG_DESC4 = "***";
                }
                else
                    ety.CHRG_DESC4 = cboFeeWayId.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboCntr_Siz_Cod_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboCntr_Siz_Cod.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT7 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT7 = "***";
                    ety.CHRG_DESC7 = "***";
                }
                else
                    ety.CHRG_DESC7 = cboCntr_Siz_Cod.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboUnit.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.UNIT = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                    ety.UNIT = "***";
                else
                    ety.UNIT = cboUnit.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboItem_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboItem.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.ITEM = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.ITEM = "***";
                    ety.ITEM_DESC = "***";
                }
                else
                    ety.ITEM_DESC = cboItem.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboCntrCoprCod_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboCntrCoprCod.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT2 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT2 = "***";
                    ety.CHRG_DESC2 = "***";
                }
                else
                    ety.CHRG_DESC2 = cboCntrCoprCod.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboWorkWayId_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboWorkWayId.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT5 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT5 = "***";
                    ety.CHRG_DESC5 = "***";
                }
                else
                    ety.CHRG_DESC5 = cboWorkWayId.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboCntr_Typ_Cod_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboCntr_Typ_Cod.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT8 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT8 = "***";
                    ety.CHRG_DESC8 = "***";
                }
                else
                    ety.CHRG_DESC8 = cboCntr_Typ_Cod.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboIeId_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboIeId.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT3 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT3 = "***";
                    ety.CHRG_DESC3 = "***";
                }
                else
                    ety.CHRG_DESC3 = cboIeId.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }

        private void cboWeight_SelectedIndexChanged(object sender, EventArgs e)
        {
            IList<etyBillPrice> ilSrc = srcBinding.DataSource as IList<etyBillPrice>;
            if (ilSrc == null || ilSrc.Count < 1)
                return;
            string cboValue = cboWeight.Value;
            foreach (etyBillPrice ety in ilSrc)
            {
                ety.CHRG_FLT6 = cboValue;
                if (string.IsNullOrWhiteSpace(cboValue) || cboValue == "***")
                {
                    ety.CHRG_FLT6 = "***";
                    ety.CHRG_DESC6 = "***";
                }
                else
                    ety.CHRG_DESC6 = cboWeight.GetValue("CODE_DESC");

            }
            for (int i = 0; i < ilSrc.Count; i++)
                srcBinding.ResetItem(i);
        }



    }
}
